package some.member.profil.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import some.member.domain.MemberCommand;
import some.member.profil.dao.IdealMemberDao;
import some.member.profil.domain.IdealMemberCommand;
import some.point.dao.Point;

@Controller
@RequestMapping("/ideal.do")
public class IdealController {
	
	private Logger log = Logger.getLogger(this.getClass());
	
	@Autowired
	private IdealMemberDao idealDao;
	
	@Autowired
	private Point point;

	public void setIdealDao(IdealMemberDao idealDao) {
		this.idealDao = idealDao;
	}


	@RequestMapping(method=RequestMethod.GET)
	public ModelAndView form(@RequestParam("id")String id){
		ModelAndView mav = new ModelAndView("idealMember");
		mav.addObject("idealCommand", new IdealMemberCommand());
		mav.addObject("id",id);
		return mav;
	}
	
	@RequestMapping(method=RequestMethod.POST)
	public ModelAndView submit(@ModelAttribute("idealCommand") IdealMemberCommand idealCommand){
		
		if(log.isDebugEnabled()){
			log.debug("idealCommand : " + idealCommand);
		}

		idealDao.idealInsertMember(idealCommand);
		
		ModelAndView mav = new ModelAndView("main");
		mav.addObject("memberCommand",new MemberCommand());
				
		return mav;
	}
}

